package Zoo.view.leaderview;

import Zoo.entity.ZooparkEntity;
import Zoo.handler.UpdateZooparkViewHandler;

import javax.swing.*;
import java.awt.*;
import java.sql.Date;

/**
 * 1、UpdateZooparkView用于园长修改园区
 */
public class UpdateZooparkView extends JDialog {
    JPanel jPanel = new JPanel();
    //此处是通过园区id来找对应园区，所以不能修改园区id，
    JLabel idLable = new JLabel("修改的园区id");
    JTextField idTxt = new JTextField();
    JLabel kindLable = new JLabel("展区类型");
    JTextField kindTxt = new JTextField();
    JLabel introductionLable = new JLabel("简介");
    JTextField introductionTxt = new JTextField();
    JLabel areaLable = new JLabel("占地面积");
    JTextField areaTxt = new JTextField();
    JLabel addressLable = new JLabel("地址");
    JTextField addressTxt = new JTextField();
    JLabel beginLable = new JLabel("开始时间");
    JTextField beginTxt = new JTextField();
    JLabel finishLable = new JLabel("结束时间");
    JTextField finishTxt = new JTextField();
    JLabel adminidLable = new JLabel("园区管理员id");
    JTextField adminidTxt = new JTextField();
    JButton updateBtn = new JButton("修改");

    UpdateZooparkViewHandler updateZooparkViewHandler;

    public UpdateZooparkView(LeaderView leaderView) {
        super(leaderView, "修改园区信息", true);

        updateZooparkViewHandler = new UpdateZooparkViewHandler(this, leaderView);


        idLable.setPreferredSize(new Dimension(80, 30));
        jPanel.add(idLable);
        idTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(idTxt);

        kindLable.setPreferredSize(new Dimension(80, 30));
        jPanel.add(kindLable);
        kindTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(kindTxt);

        introductionLable.setPreferredSize(new Dimension(80, 30));
        jPanel.add(introductionLable);
        introductionTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(introductionTxt);

        areaLable.setPreferredSize(new Dimension(80, 30));
        jPanel.add(areaLable);
        areaTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(areaTxt);

        addressLable.setPreferredSize(new Dimension(80, 30));
        jPanel.add(addressLable);
        addressTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(addressTxt);

        beginLable.setPreferredSize(new Dimension(80, 30));
        jPanel.add(beginLable);
        beginTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(beginTxt);

        finishLable.setPreferredSize(new Dimension(80, 30));
        jPanel.add(finishLable);
        finishTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(finishTxt);

        adminidLable.setPreferredSize(new Dimension(80, 30));
        jPanel.add(adminidLable);
        adminidTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(adminidTxt);

        Container contentPane = getContentPane();
        contentPane.add(jPanel);

        updateBtn.addActionListener(updateZooparkViewHandler);
        jPanel.add(updateBtn);

        setSize(350, 500);
        setLocationRelativeTo(null);
        //DISPOSE_ON_CLOSE：只销毁当前的窗体
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setResizable(false);
        setVisible(true);


    }

    //获取修改后的园区对象（但园区id是需要修改对象的园区id）
    public ZooparkEntity buildUpdatedZooparkEntity() {
        ZooparkEntity zooparkEntity = new ZooparkEntity();
        zooparkEntity.setId(Integer.valueOf(idTxt.getText()));
        zooparkEntity.setKind(kindTxt.getText());
        zooparkEntity.setIntroduction(introductionTxt.getText());
        zooparkEntity.setArea(areaTxt.getText());
        zooparkEntity.setAddress(addressTxt.getText());
        zooparkEntity.setBeginTime(Date.valueOf(beginTxt.getText()));
        zooparkEntity.setFinishTime(Date.valueOf(finishTxt.getText()));
        zooparkEntity.setAdminId(adminidTxt.getText());


        return zooparkEntity;
    }
}
